package com.project.biz.impl;

import com.project.biz.I18nBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;

/**
 * @Description: i18n国际化业务层接口实现类
 * @Author: zhuchi
 * @CreateDate: 2020/8/7 16:26
 * @Version: 1.0
 */
@Service
public class I18nBizImpl implements I18nBiz {

    @Autowired
    private MessageSource messageSource;

    /**
     * 根据键值获取国际化Value值
     * @param key
     * @return
     */
    public String getMessage(String key){
        String message = messageSource.getMessage(key, new String[]{"",""}, LocaleContextHolder.getLocale());
        return message;
    }

    /**
     * 根据键值获取国际化Value值
     * @param key
     * @param param 国际化内容中的参数
     * @return
     */
    public String getMessage(String key, String [] param){
        String message = messageSource.getMessage(key, param, LocaleContextHolder.getLocale());
        return message;
    }

    /**
     * 获取操作成功提示
     * @return
     */
    public String selectSuccessMessage(){
        return this.getMessage("msg.selectSuccess");
    }

    /**
     * 获取操作成功提示
     * @return
     */
    public String operationSuccessMessage(){
        return this.getMessage("msg.operationSuccess");
    }

}
